package com.hddf.project.service;

import com.hddf.project.base.BaseService;
import com.hddf.project.pojos.Logs;
import com.hddf.project.pojos.User;
import com.hddf.project.util.O;

public class LogsService extends BaseService {

	private static LogsService ls = null;

	static {
		if (null == ls) {
			ls = new LogsService();
		}
	}

	public static LogsService getInService() {
		return ls;
	}

	/**
	 * 添加日志
	 * 
	 * @param userId
	 * @param content
	 * @param type
	 */
	public void addLog(Integer userId, String content, Short type) {
		try {
			Logs l = new Logs();
			l.setUserId(userId);
			l.setContent(content);
			l.setType(type);
			l.setImplTime(O.getTimestamp3());
			super.addObject(l);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 添加日志
	 * 
	 * @param userId
	 * @param content
	 * @param type
	 *            : 1添加，2修改，3删除，4浏览
	 */
	public void addLog(User user, String content, Short type) {
		try {
			Logs l = new Logs();
			l.setUserId(user.getId());
			l.setContent(user.getUsername() + "于" + O.getTimestamp3() + "：" + content);
			l.setType(type);
			l.setImplTime(O.getTimestamp3());
			super.addObject(l);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
